[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
getchar() Read a Character from 'Stdin' (Macro)
#include <stdio.h>
int getchar(void);
getchar() reads a single character from the stream 'stdin'.
Returns: The character read, if successful. getchar() returns
the value of EOF if there is an error or end-of-file
condition.
Notes: Use feof() or ferror() to determine whether an error
or end-of-file condition occurred.
getchar() is equivalent to getc(stdin). getchar() is
similar to fgetchar(), but getchar() is a macro,
while fgetchar() is a function.
-------------------------------- Example ---------------------------------
The following statements get characters from 'stdin' and store them
in 'string' until a new-line character is read. The string is then
printed.
#include <stdio.h>
char string[81];
int i;
char ch;
main()
{
i = 0;
while ((ch = getchar()) != '\n')
string[i++] = ch;
printf("\n%s\n",string);
}
See Also:
getc()
fgetc()
fgetchar()
feof()
ferror()
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson